<template>
	<view  class="main">
			<view style="display: flex;justify-content: center;">
				<uni-forms ref="form" :modelValue="formData" :rules="rule" style="display: flex;flex-direction: column;align-items: center;">
					<uni-forms-item label="账号" name="account" >
						<input class="input" type="text" v-model="formData.account" placeholder="请输入邮箱" />
					</uni-forms-item>
					<uni-forms-item label="密码" name="password" >
						<input class="input" v-model="formData.password" type="password" placeholder="请输入密码" />
					</uni-forms-item>
					
				</uni-forms>
			</view>
			
			<view style="display: flex;flex-direction: row;justify-content: space-around;">
				<button style="width:40%; background-color: #4CAF50; border: none; color: white; padding: 10px 20px; text-align: center; text-decoration: none; display: inline-block;font-size: 16px;margin: 4px 2px;cursor: pointer;" @click="login">登录</button>
				<button style="width:40%; background-color: #4CAF50; border: none; color: white; padding: 10px 20px; text-align: center; text-decoration: none; display: inline-block;font-size: 16px;margin: 4px 2px;cursor: pointer;" @click="register">注册</button>
				
			</view>
		
		
		<!-- <image src="@/static/login.png"></image> -->
		
	</view>
</template>

<script>
	import  nav from "@/pages/index/navv/nav.js"
	
	export default {
		data() {
			return {
				formData:{
					account:"",
					password:"" 
				},
				rule:{}
			}
		},
		methods: {
			...nav,
			register(){
				uni.reLaunch({
					url:"/pages/index/register/register"
				})
			},
			login(){ 
				let t=this;
				
				uni.request({
					method:"POST",
					url:"http://localhost:3000/login",
					data:JSON.stringify(this.formData),
					dataType:"application/json",
					success(data) {
						
						let temp=JSON.parse(data.data)
						if(temp[0] == null || temp[0] == undefined){
							uni.showToast({
								title:"账号或密码错误！",
								icon:"error",
								
								
							})
							return;
						}
						console.log("data:",temp)
						t.$store.commit("setAccount",temp[0].account)
						t.$store.commit("setNickName",temp[0].nick_name)
						t.$store.commit("setUserType",temp[0].type)
						if(t.$store.getters.userType == "0"){
							t.skipToShouye();
						}
						else{
							uni.navigateTo({
								url:"/pages/index/kitchen/kitchen",
								success() {
									console.log(8674874)
								}
							})
						}
						
					} 
				})
				
				
			}
		}
	}
</script>

<style>
.main{
	background-image: url(@/static/login.png);
	background-size: cover;
	background-repeat: no-repeat;
	background-position: center center;
	height: 1600rpx;
	display: flex;
	flex-direction: column;
	justify-content: space-around;
	
}
.input {
    appearance: none;
    text-align: center;
    height: 36px;
    width: 248px;
    border-radius: 15px;
    border: 0px solid #fff;
    
    outline: 0;
    letter-spacing: 1px;
    color: black;
    font-weight: 600;
    background: rgba(234, 234, 234, 0.1);
    border: 1px solid rgba(255,255,255,.15);
    box-shadow: 0 2px 3px 0 rgba(0,0,0,.1) inset;
    text-shadow: 0 1px 2px rgba(0,0,0,.1);
    -o-transition: all .2s;
    -moz-transition: all .2s;
    -webkit-transition: all .2s;
    -ms-transition: all .2s;
	
}

</style>
